//
//  DeliveryPartsInfoTC.m
//  ProjectforHDX
//
//  Created by HDX on 16/8/9.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "DeliveryPartsInfoTC.h"

#define TOPMARGIN 5
#define LEFTEMARGIN 10
#define LABHEIGHT 24

@interface DeliveryPartsInfoTC()

@property(nonatomic,strong) UIView *cellContentView;

 /**
 *  板件名
 */
@property (nonatomic, strong) RZCustomLable *nameLab;
/**
 *  板件号
 */
@property (nonatomic, strong) RZCustomLable *codeLab;
/**
 *  板件序列号
 */
@property (nonatomic, strong) RZCustomLable *snLab;
/**
 *  板件版本
 */
@property (nonatomic, strong) RZCustomLable *vsLab;

/**
 *  货位
 */
@property (nonatomic, strong) RZCustomLable *vsLation;
/**
 *  线
 */
@property (nonatomic, strong) RZCustomLable *line;

/**
 *  修改按钮
 */
//@property (nonatomic, strong) RZCustomButtom *modifyBtn;
@end

@implementation DeliveryPartsInfoTC

- (void)setModifyPermission:(NSString *)modifyPermission{
}

- (void)setData:(NSDictionary *)data {
    
    if (_data != data) {
        _data=data;
        
        self.cellContentView=[[UIView alloc] init];
        [self.cellContentView setClipsToBounds:YES];
        [self.cellContentView setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        [self addSubview:self.cellContentView];
        
        self.nameLab =[[RZCustomLable alloc] init ];
  
        self.nameLab.font = CustomFont(13);
        self.nameLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.nameLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.nameLab];
        
        self.codeLab = [[RZCustomLable alloc] init];
 
        self.codeLab.font = CustomFont(13);
        self.codeLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.codeLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.codeLab];
        
        self.vsLab = [[RZCustomLable alloc] init ];
    
  
        self.vsLab.font = CustomFont(13);
        self.vsLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.vsLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.vsLab];
        
        
        self.snLab = [[RZCustomLable alloc] init ];
        
        self.snLab.font = CustomFont(13);
        self.snLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.snLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.snLab];
        
        self.vsLation = [[RZCustomLable alloc] init ];
        self.vsLation.font = CustomFont(13);
        self.vsLation.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.vsLation.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.vsLation];
        

        
        
        self.line = [[RZCustomLable alloc] init ];
        self.line.backgroundColor = [UtilCheck hexStringToColor:@"EcEcEc" alpha:1];
        [self.cellContentView addSubview:        self.line];
       
    }
    
    
}

- (void)layoutSubviews {
 
    [self.cellContentView setFrame:CGRectMake(0, 0, self.width, self.height)];
   
    CGFloat width= self.width / 2.f-10;
    CGFloat width2 = self.width * 2/ 5;

    //板件名称
    [self.nameLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN, width, LABHEIGHT)];
    
    self.nameLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_data objectForKey:@"partsName"]];
    [self.nameLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateName"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.nameLab sizeToFit];
   
    self.nameLab.left=LEFTEMARGIN;
    if(self.nameLab.height<LABHEIGHT){
        self.nameLab.height=LABHEIGHT;
    }
    //版本号
    [self.vsLab setFrame:CGRectMake(self.nameLab.left, self.nameLab.bottom, width,LABHEIGHT)];
    self.vsLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_data objectForKey:@"partsVersion"]];
   [self.vsLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateCode"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.vsLab sizeToFit];
    self.vsLab.left=LEFTEMARGIN;
    if(self.vsLab.height<LABHEIGHT){
        self.vsLab.height=LABHEIGHT;
    }
    //货位
    [self.vsLation setFrame:CGRectMake(self.vsLab.left, self.vsLab.bottom, width,LABHEIGHT)];
    self.vsLation.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.goodLocation"],[_data objectForKey:@"location"]];
       [self.vsLation textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"seeting.goodLocation"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.vsLation sizeToFit];
    self.vsLation.left=LEFTEMARGIN;
    if(self.vsLation.height<LABHEIGHT){
        self.vsLation.height=LABHEIGHT;
    }
    //版件号
    [ self.codeLab setFrame:CGRectMake(width2+LEFTEMARGIN+10, TOPMARGIN, width,LABHEIGHT)];
    self.codeLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_data objectForKey:@"partsCode"]];
      [self.codeLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateNO"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.codeLab sizeToFit];
    self.codeLab.left=width2+10+LEFTEMARGIN;
    if(self.codeLab.height<LABHEIGHT){
        self.codeLab.height=LABHEIGHT;
    }
    //序列号
    [self.snLab setFrame:CGRectMake(width2+10+LEFTEMARGIN, self.codeLab.bottom, width,LABHEIGHT)];
    self.snLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_data objectForKey:@"partsSN"]];
      [self.snLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateSerial"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.snLab sizeToFit];
    self.snLab.left=width2+10+LEFTEMARGIN;
    if(self.snLab.height<LABHEIGHT){
        self.snLab.height=LABHEIGHT;
    }
    
    // 添加长按复制功能
    self.snLab.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureAction:)];
    [self.snLab addGestureRecognizer:gesture];
    
    //线
    [self.line setFrame:CGRectMake(0, self.cellContentView.height - 0.5f, self.width, 0.5f)];
    
    //修改按钮
    
//    [self.modifyBtn setFrame:CGRectMake(self.width - 50, TOPMARGIN, 50, LABHEIGHT + 5)];
    
}

-(CGFloat)createStepView{
    CGFloat height=0;
    CGFloat width= BOUNDSWIDTH / 2.f-10;
    CGFloat width2 = 10;
    //板件名称
    [self.nameLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN, width, LABHEIGHT)];
    self.nameLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_data objectForKey:@"name"]];
    [self.nameLab sizeToFit];
    self.nameLab.left=LEFTEMARGIN;
    if(self.nameLab.height<LABHEIGHT){
        self.nameLab.height=LABHEIGHT;
    }
    //版本号
    [self.vsLab setFrame:CGRectMake(self.nameLab.left, self.nameLab.bottom, width,LABHEIGHT)];
    self.vsLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_data objectForKey:@"version"]];
    [self.vsLab sizeToFit];
    self.vsLab.left=LEFTEMARGIN;
    if(self.vsLab.height<LABHEIGHT){
        self.vsLab.height=LABHEIGHT;
    }
    //货位
    [self.vsLation setFrame:CGRectMake(self.vsLab.left, self.vsLab.bottom, width,LABHEIGHT)];
    self.vsLation.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_data objectForKey:@"version"]];
    [self.vsLation sizeToFit];
    self.vsLation.left=LEFTEMARGIN;
    if(self.vsLation.height<LABHEIGHT){
        self.vsLation.height=LABHEIGHT;
    }
    //版件号
    [ self.codeLab setFrame:CGRectMake(width2+LEFTEMARGIN+10 , TOPMARGIN, width,LABHEIGHT)];
    self.codeLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_data objectForKey:@"code"]];
    [self.codeLab sizeToFit];
    self.codeLab.left=LEFTEMARGIN;
    if(self.codeLab.height<LABHEIGHT){
        self.codeLab.height=LABHEIGHT;
    }
    //序列号
    [self.snLab setFrame:CGRectMake(width2+10+LEFTEMARGIN, self.codeLab.bottom, width,LABHEIGHT)];
    self.snLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_data objectForKey:@"sn"]];
    [self.snLab sizeToFit];
    self.snLab.left=LEFTEMARGIN;
    if(self.snLab.height<LABHEIGHT){
        self.snLab.height=LABHEIGHT;
    }
    height=self.vsLation.bottom+TOPMARGIN;
    if(height<self.snLab.bottom+TOPMARGIN){
         height=self.snLab.bottom+TOPMARGIN;
    }
    
    return height;
    
}


/**
 长按复制

 @param sender
 */
- (void)longPressGestureAction:(UILongPressGestureRecognizer *)sender {
    
    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    
    NSString * labelString = ((UILabel *)sender.view).text;
    NSString *titleStrng = [THMangerTool language:@"setting.plateSerial"];
    
    NSRange rang = NSMakeRange(titleStrng.length + 1, labelString.length - titleStrng.length - 1);
    
    NSString *pastString = [labelString substringWithRange:rang];
    
    if (![Toolobject IsEmptyString:pastString]) {
        pboard.string = pastString;
        [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.copySNSuccess"]];
    }
    else {
        [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.SNEmpty"]];
    }
}

@end
